const reqlib = require('app-root-path').require
const webDataUtil = reqlib('/app/util/webDataUtil')

// function parseValue (val) {
//   return parseFloat(val || 0) || 0
// }

// 合约执行买入
module.exports = async function exBuy ({
  usdtKey,
  quantity,
  btbItem,
  btbLeverage
}) {
  if (!quantity) {
    return false
  }
  await webDataUtil.binance('futuresLeverage', {
    key: usdtKey,
    quantity: btbLeverage || 1
  })
  // 执行
  const buyRes = await webDataUtil.binance('futuresMarketBuy', {
    key: usdtKey,
    quantity: quantity
  })
  // orderId: 5532731189,
  //   symbol: 'OPUSDT',
  //   status: 'NEW',
  //   clientOrderId: 'I6d46FfTzRBBojnrtd9O2d',
  //   price: '0.0000000',
  //   avgPrice: '0.00',
  //   origQty: '3.7',
  //   executedQty: '0.0',
  //   cumQty: '0.0',
  //   cumQuote: '0.00000000',
  //   timeInForce: 'GTC',
  //   type: 'MARKET',
  //   reduceOnly: false,
  //   closePosition: false,
  //   side: 'SELL',
  //   positionSide: 'BOTH',
  //   stopPrice: '0.0000000',
  //   workingType: 'CONTRACT_PRICE',
  //   priceProtect: false,
  //   origType: 'MARKET',
  //   updateTime: 1689323145432
  const resData = buyRes.data || {}
  if (!resData.orderId) {
    return false
  }
  return {}
}
